{
LANG : PASCAL
PROB : clocks
}

program CLOCKS;
const
  fi = 'clocks.in';
  fo = 'clocks.out';
  d : array[1..9, 1..9] of byte = (
  (1, 1, 0, 1, 1, 0, 0, 0, 0),
  (1, 1, 1, 0, 0, 0, 0, 0, 0),
  (0, 1, 1, 0, 1, 1, 0, 0, 0),
  (1, 0, 0, 1, 0, 0, 1, 0, 0),
  (0, 1, 0, 1, 1, 1, 0, 1, 0),
  (0, 0, 1, 0, 0, 1, 0, 0, 1),
  (0, 0, 0, 1, 1, 0, 1, 1, 0),
  (0, 0, 0, 0, 0, 0, 1, 1, 1),
  (0, 0, 0, 0, 1, 1, 0, 1, 1));
var
  a : array[1..9] of byte;
  s : array[0..4] of byte;
  p, res : array[1..100] of byte;
  l, best : integer;

procedure inp;
var
  i : integer;
begin
  fillchar(s, sizeof(s), 0);
  for i := 1 to 9 do
  begin
    read(a[i]);
    a[i] := a[i] div 3;
    a[i] := a[i] mod 4;
    inc(s[a[i]]);
  end;
end;

procedure update(k : integer);
var
  i : integer;
begin
  inc(l, p[k]);
  for i := 1 to 9 do
    if d[k, i] = 1 then
    begin
      dec(s[a[i]]);
      a[i] := (a[i]+p[k]) mod 4;
      inc(s[a[i]]);
    end;
end;

procedure return(k : integer);
var
  i : integer;
begin
  dec(l, p[k]);
  for i := 1 to 9 do
    if d[k, i] = 1 then
    begin
      dec(s[a[i]]);
      a[i] := (a[i]+4-p[k]) mod 4;
      inc(s[a[i]]);
    end;
end;

procedure try(k : integer);
var
  i : integer;
begin
  if best < l then exit;
  if k = 10 then
  begin
    if s[0] = 9 then
    begin
      best := l;
      res := p;
    end;
    exit;
  end;
  for i := 0 to 3 do
  begin
    p[k] := i;
    update(k);
    try(k+1);
    return(k);
  end;
end;

procedure process;
begin
  fillchar(p, sizeof(p), 0);
  fillchar(res, sizeof(res), 0);
  l := 0;
  best := 1000;
  try(1);
end;

procedure out;
var
  i, j : integer;
  q : array[1..100] of integer;
begin
  l := 0;
  for i := 1 to 9 do
    for j := 1 to res[i] do
    begin
      inc(l);
      q[l] := i;
    end;
  write(q[1]);
  for i := 2 to l do write(' ', q[i]);
  writeln;
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  inp;
  process;
  out;
  close(output);
  close(input);
end.